//
//  NewHomeMenuView.m
//  NewPro
//
//  Created by RYX on 2019/4/18.
//  Copyright © 2019 何荧红. All rights reserved.
//

#import "NewHomeMenuView.h"
#import "NewHomeMenuCell.h"
#import "NewHomeServiceModel.h"
#import "TraditionPOSListVC.h"
#import "InvitePartnerViewController.h"
#import "MyProfitViewController.h"
#import "NewKnowledgeViewController.h"
#import "ActivityViewController.h"
#import "PosApplyViewController.h"
#import "CompanyNewsViewController.h"
#import "CYYServiceViewController.h"
#import "HomeList.h"

#import "CalendarSignInViewController.h"
#import "NewTodayEarningsViewController.h"
#import "RankingListViewController.h"

@interface NewHomeMenuView ()<UICollectionViewDelegate,UICollectionViewDataSource>

@property (nonatomic,strong) UICollectionView *collectionView;
@property (nonatomic,copy) NSArray *listArr;
@property (nonatomic,copy) NSArray *vcArr;
@end

@implementation NewHomeMenuView

- (NSArray *)vcArr{
    
    if (!_vcArr) {
        
        _vcArr = @[[PosApplyViewController class],[TraditionPOSListVC class],[NewTodayEarningsViewController class],[RankingListViewController class],[CalendarSignInViewController class],[NewKnowledgeViewController class],[ActivityViewController class],[InvitePartnerViewController class]];
    }
    
    return _vcArr;
}


- (NSArray *)listArr{
    
    if (!_listArr) {
        
        NewHomeServiceModel *model1 = [[NewHomeServiceModel alloc] init];
        model1.title = @"机具申领";
        model1.img = @"首页机具申领";
        
        NewHomeServiceModel *model2 = [[NewHomeServiceModel alloc] init];
        model2.title = @"终端管理";
        model2.img = @"首页商户管理";
        
        NewHomeServiceModel *model3 = [[NewHomeServiceModel alloc] init];
        model3.title = @"当日收益";
        model3.img = @"首页我的收益";
        
        NewHomeServiceModel *model4 = [[NewHomeServiceModel alloc] init];
        model4.title = @"业绩排行";
        model4.img = @"业绩排行";
        
        NewHomeServiceModel *model5 = [[NewHomeServiceModel alloc] init];
        model5.title = @"每日签到";
        model5.img = @"每日签到";
        
        NewHomeServiceModel *model6 = [[NewHomeServiceModel alloc] init];
        model6.title = @"知识讲堂";
        model6.img = @"首页知识讲堂";
        
        NewHomeServiceModel *model7 = [[NewHomeServiceModel alloc] init];
        model7.title = @"活动专区";
        model7.img = @"活动专区";
        
        NewHomeServiceModel *model8 = [[NewHomeServiceModel alloc] init];
        model8.title = @"我要分享";
        model8.img = @"首页分享";
        
        _listArr = @[model1, model2, model3, model4, model5, model6, model7, model8];
    }
    return _listArr;
}

- (UICollectionView *)collectionView{
    
    if (!_collectionView) {
        
        UICollectionViewFlowLayout * flowLayout = [[UICollectionViewFlowLayout alloc] init];
        flowLayout.minimumLineSpacing = 0;
        flowLayout.minimumInteritemSpacing = 0;
        flowLayout.itemSize = CGSizeMake(ScreenWidth / 4, 70);
        _collectionView = [[UICollectionView alloc] initWithFrame:CGRectZero collectionViewLayout:flowLayout];
        _collectionView.backgroundColor = UIColor.whiteColor;
        [_collectionView registerNib:[UINib nibWithNibName:@"NewHomeMenuCell" bundle:[NSBundle mainBundle]] forCellWithReuseIdentifier:@"CELL"];
        _collectionView.delegate = self;
        _collectionView.dataSource = self;
    
    }
    
    return _collectionView;
}

- (instancetype)initWithFrame:(CGRect)frame{
    
    if (self = [super initWithFrame:frame]) {
        
        self.backgroundColor = UIColor.whiteColor;
        [self setUI];
    }
    return self;
}

- (void)setUI{
    
    [self addSubview:self.collectionView];
    
    [self.collectionView  mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.left.right.top.bottom.equalTo(self);
    }];
}

- (NSInteger) numberOfSectionsInCollectionView:(UICollectionView *)collectionView{
    
    return 1;
    
}

- (NSInteger) collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section{
    
    return self.listArr.count;
    
}

- (UICollectionViewCell *) collectionView:(UICollectionView *) collectionView cellForItemAtIndexPath:(nonnull NSIndexPath *)indexPath{
    
    NewHomeMenuCell * cell = (NewHomeMenuCell *)[collectionView dequeueReusableCellWithReuseIdentifier:@"CELL" forIndexPath:indexPath];
    cell.model = self.listArr[indexPath.row];
    
    return cell;
    
}

- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath{
    
    if (![[HomeList sharedInstance].hadRealName isEqualToString:@"4"]) {
        
        if (self.delegate && [self.delegate respondsToSelector:@selector(judgeIfHadRealName)]) {
            
            [self.delegate judgeIfHadRealName];
            return;
        }
        return;
    }
    
    UIViewController *VC = [[self.vcArr[indexPath.row] alloc] init];
    [VC setHidesBottomBarWhenPushed:YES];
    [[self getCurrentViewController].navigationController pushViewController:VC animated:YES];
}
@end
